module("Game", package.seeall )

BUILD = 1
FIGHT = 2
SCOREBOARD = 3

StateNames = {
	[BUILD] = "BUILD",
	[FIGHT] = "FIGHT",
	[SCOREBOARD] = "SCOREBOARD"
}

local GameState = CreateConVar("nc_gamestate", BUILD,  {FCVAR_REPLICATED} )
local GameStartTime = CreateConVar("nc_roundstart", CurTime(),  {FCVAR_REPLICATED} )
local GameRound = CreateConVar("nc_round", 1,  {FCVAR_REPLICATED} )
local GameMaxRound = CreateConVar("nc_max_round", 3,  {FCVAR_REPLICATED} )
local BuildPhaseLength = CreateConVar("nc_buildlength", 300,  {FCVAR_REPLICATED} )
local FightPhaseLength = CreateConVar("nc_fightlength", 450,  {FCVAR_REPLICATED} )


function Round()
	return GameRound:GetInt()
end

function MaxRound()
	return GameMaxRound:GetInt()
end

function Length()
	if State() == BUILD then
		return BuildPhaseLength:GetInt()
	elseif State() == SCOREBOARD then
		return 5
	end
	return FightPhaseLength:GetInt()
end

function StartTime()
	return GameStartTime:GetInt()
end

function State()
	return CurrentGameState or GameState:GetInt()
end

function StateName()
	return StateNames[ State() ]
end

function TimeLeft()
	local End = StartTime() + Length()
	
	return math.max( 0, End - CurTime() )
end